/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.belfalas.simy86.operadores;

import org.belfalas.simy86.Y86;

/**
 *
 * @author belfalas
 */
public class MRMOVL extends Operador{

    public void fetch(org.belfalas.simy86.Operador_Stat stat) {
        stat.reg = Y86.memoria.readUnsignedByte(stat.pc+1);
        stat.rA = getRA(stat.reg);
        stat.rB = getRB(stat.reg);
        stat.rA.incUsage();
        stat.rB.incUsage();
        stat.valC = Y86.memoria.readSignedWord(stat.pc+2);
        stat.valP = stat.pc+6;
        stat.predicted_pc = stat.valP;
    }

    public void decode(org.belfalas.simy86.Operador_Stat stat) {
        stat.valB = stat.rB.reg;        
        
    }

    public void execute(org.belfalas.simy86.Operador_Stat stat) {
        stat.rB.decUsage();
        stat.valE = stat.valB+stat.valC;
    }

    public void memory(org.belfalas.simy86.Operador_Stat stat) {
        try {
            if (stat.pc == 0x8e || stat.pc == 0x102) {
                //System.out.println("valE: "+stat.valE);
                //System.out.println("valM: "+stat.valM);
            }
            stat.valM = Y86.memoria.readSignedWord(stat.valE);
        } catch (IndexOutOfBoundsException ex){
            System.out.println(stat.pc);
            throw ex;
        }
        //System.out.println(stat.rA +"<="+stat.valM+" from "+stat.valE);
    }

    public void writeback(org.belfalas.simy86.Operador_Stat stat) {
        stat.rA.reg = stat.valM;
        stat.rA.decUsage();
        //PC.position = stat.valP;
    }

    
}
